<template>
  <BasicTable @register="registerTable">
    <template #action="{ record }">
      <TableAction
        :actions="[
          {
            icon: 'clarity:note-edit-line',
            tooltip: '确定',
            onClick: handleEdit.bind(null, record),
          },
        ]"
      />
    </template>
  </BasicTable>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { columns } from './safeConfiguration.data';
  import { getConfigEditSecurityPage, getConfigUpdateSecurity } from '/@/api/flowManage/flowManage';
  import { useMessage } from '/@/hooks/web/useMessage';
  export default defineComponent({
    name: 'SafeConfiguration',
    components: { BasicTable, TableAction },
    setup() {
      const [registerTable, { reload, setProps }] = useTable({
        title: '',
        api: getConfigEditSecurityPage,
        rowKey: 'id',
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: [],
          autoSubmitOnEnter: true,
        },
        useSearchForm: false,
        showTableSetting: false,
        bordered: true,
        showIndexColumn: false,
        canResize: false,
        pagination: false,
        scroll: { y: window?.innerHeight - 260 },
        // showHeader: false,
        actionColumn: {
          width: 60,
          title: '操作',
          dataIndex: 'action',
          colSpan: 0,
          slots: { customRender: 'action' },
        },
      });
      const { createMessage } = useMessage();

      const handleEdit = async (record) => {
        try {
          handleSetProps(true);
          await getConfigUpdateSecurity(record);
          createMessage.success('操作成功');
          reload();
        } finally {
          handleSetProps(false);
        }
      };
      const handleSetProps = (bool) => {
        setProps({ loading: bool });
      };

      return {
        registerTable,
        handleEdit,
      };
    },
  });
</script>
